package com.nuoniu.sibanyun.service.crm.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.entity.crm.CrmUserSearch;
import com.nuoniu.sibanyun.mapper.crm.CrmUserSearchMapper;
import com.nuoniu.sibanyun.service.crm.ICrmUserSearchService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 查询视图 服务实现类
 * </p>
 *
 * @author baiqiang
 * @since 2020-06-20
 */
@Service
public class CrmUserSearchServiceImpl extends ServiceImpl<CrmUserSearchMapper, CrmUserSearch> implements ICrmUserSearchService {

    @Resource
    private CrmUserSearchMapper searchMapper;

    @Override
    public List<CrmUserSearch> getUserSearch(Integer searchType) {
        UserInfo userInfo = UserThreadLocal.get();
        return searchMapper.getUserSearch(searchType, userInfo.getUserId());
    }

    @Override
    public void deleteOne(Integer id) {
        UserInfo userInfo = UserThreadLocal.get();
        HashMap<String,Object> removeMap = new HashMap<>();
        removeMap.put("id",id);
        removeMap.put("create_user_id",userInfo.getUserId());
        boolean b = removeByMap(removeMap);
        if(!b){
            throw new NuoNiuException("删除失败");
        }
    }
}
